<template>
		
	<view class="login">
		<form @submit="formSubmit">
		<view class="content-wrapper">
			<view class="title">
				<!-- <h1>欢迎登录</h1> -->
			</view>
		<!-- 	<view style="text-align: center;" >
				<image src="../../../../static/panpan.jpg"  style="width: 160rpx;height: 160rpx;"></image>
			</view> -->
			
		
				<view class="login-form">
					<view class="login-form-items">
						<view class="login-form-items-title">  <image src="../../static/login.png" style="width: 50rpx;height: 50rpx;"></image></view>
						<input type="text" class="login-input" name="username" placeholder="请输入绑定账号" />
					</view>
				
					<view class="login-form-items">
						<view class="login-form-items-title"><image src="../../static/pwd.png" style="width: 50rpx;height: 50rpx;"></image></view>
						<input type="password" name="password" class="login-input"    placeholder="请输入登录密码" />
					</view>
					
					<view class="login-form-items">
						<view class="login-form-items-title"><image src="../../static/pwd.png" style="width: 50rpx;height: 50rpx;"></image></view>
						<input type="password" name="passwordRepeat" class="login-input"    placeholder="请重复登录密码" />
					</view>
				           
				</view>
			
		</view>
		<div class="submit-wrapper">
			<button type="primary" form-type="submit" class="login-btn">绑定账号</button>
		</div>
		
		</form>
		<!-- <button type="warn" @click="register" style="margin: 20rpx 20rpx 20rpx 20rpx;" class="login-btn">注册</button> -->
		
	</view>
</template>

<script>
	export default {
		onLoad(options){
			console.log(options);
			this.user=JSON.parse(options.user)
			console.log('onLoad-----',this.user);
			this.backpage=options.backpage;
			this.backtype=options.backtype;
		},
		data() {
			return {
				user:{},
				backpage:'',
				backtype:''
			};
		},
		methods:{
			
			async loginBind(formdata) {
				            formdata.openId = this.user.openId;
							const {data:res} =await uni.$http.post('/sys_user/bind_account',formdata);
						    if(res.code=='0'){
								uni.setStorageSync('userKey',this.user);
								uni.setStorageSync('authorization',this.user.authorization);
								this.$emit('loginBack')
								
								console.log(this.backpage);
								console.log(this.backtype);
								console.log('1'==this.backtype);
								console.log('2'==this.backtype);
								if('1'==this.backtype){
									uni.redirectTo({
										url:this.backpage
									})
								}else if('2'==this.backtype){
									uni.switchTab({
										url:this.backpage
									})
									console.log('2-------------');
								}else{
									uni.switchTab({
										url: '/pages/my/my',
										animationType: 'pop-in',
										animationDuration: 200
									}); 
								}
								
							}else if(res.code == '-1'){
			
								uni.showToast({
									  	title:res.message
								})
							}
						},
			
			formSubmit: function(e) {
				              if(e.detail.value.username==''||e.detail.value.username==undefined){
								  uni.showToast({
								  	title:'用户名不能为空！'
								  })
								  return false
							  }
							  if(e.detail.value.password==''||e.detail.value.password==undefined){
							  									  uni.showToast({
							  									  	title:'密码不能为空！'
							  									  })
							  									  return false
							  }
							  
							  if(e.detail.value.passwordRepeat==''||e.detail.value.passwordRepeat==undefined){
							  									  uni.showToast({
							  									  	title:'重复密码不能为空！'
							  									  })
							  									  return false
							  }
							  if(e.detail.value.passwordRepeat!=e.detail.value.password){
							  									  uni.showToast({
							  									  	title:'密码不一致！'
							  									  })
							  									  return false
							  }
							let formdata = e.detail.value
							this.loginBind(formdata)
							
							
						},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F4F5F6;
	}

	.login {
		.content-wrapper {
			height: 99%;
			width: 100%;

			.title {
				margin-top: 10rpx;
				width: 100%;
				margin-bottom: 10px;

				h1 {
					border: 0px;
					width: 50%;
					margin: 0 auto;
					text-align: center;
					border-bottom: 1px solid #E3E3E3;
					line-height: 50px;
					font-size: 17px;
					overflow: hidden;
				}
			}

			.login-form {
				margin: 20px 10px 20px 15px;
				background: #FFFFFF;

				.login-form-items {
					padding: 15px 10px;
					border-bottom: 1px solid #F3F4F5;
					position: relative;
					display: -webkit-flex;
					display: flex;

					.login-form-items-title {
						width: 10%;
						line-height: 22px;
						flex-shrink: 0;
					}

					.login-input {
						width: 100%
					}
				}
			}
		}

		.submit-wrapper {
			padding: 10px;
			padding-top: 10px;
		}

	}
</style>

